﻿Public Class SelectServerControl
    Public Property SelectedServer As String

    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
        If Not MachineNameTextBox.Text.Contains(":") Then     MachineNameTextBox.Text += ":94"
        SelectedServer = "net.tcp://" & MachineNameTextBox.Text & "/MPQ/Server/" & ServerNameTextBox.Text
        Try
            If Not SelectedServer.EndsWith("/") Then SelectedServer += "/"
            EndpointAdr = New ServiceModel.EndpointAddress(SelectedServer)
        Catch
            MsgBox("The Server could not be found on machine " & MachineNameTextBox.Text & " with name " & ServerNameTextBox.Text)
            Exit Sub
        End Try
        Me.OK_Button.Enabled = False
        Me.MachineNameTextBox.Enabled = False
        Me.ServerNameTextBox.Enabled = False
        MainForm.Connect()
    End Sub

    Private Sub SelectServerControl_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        With My.Application.CommandLineArgs
            If .Contains("/s") Then
                MachineNameTextBox.Text = .Item(.IndexOf("/s") + 1)
                If .Contains("/sn") Then
                    ServerNameTextBox.Text = .Item(.IndexOf("/sn") + 1)
                End If
                OK_Button.PerformClick()
            End If
        End With

        If FirstPlay Then
            TutorialControl1.ShowAndMoveOn()
        End If
    End Sub
End Class
